/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interface.Hoteleria;

import Interface.Acceso;
import Interface.GUIM;
import LN.Alquileres.Habitacion;
import LN.Alquileres.Tarifa_Habitacion;
import LN.Varios.Hosteria;
import java.util.List;
import javax.swing.SwingUtilities;

/**
 *
 * @author Lukas
 */
public class Parametros_Habitacion extends javax.swing.JPanel {

    private Hosteria unaHosteria;
    private List<Tarifa_Habitacion> tarifas;
    

    public Parametros_Habitacion(Hosteria unaHosteria, Habitacion laHabitacion) {
        this.unaHosteria = unaHosteria;
        this.tarifas = unaHosteria.getTarifas_Habitacion();
       
        initComponents();
        grupo_Habilitacion.add(radio_habilitado);
        grupo_Habilitacion.add(radio_deshabilitado);
        grupo_Limpieza.add(radio_sucia);
        grupo_Limpieza.add(radio_limpia);

        for (Habitacion unaHabitacion : unaHosteria.getHabitaciones()) {
            if (unaHabitacion.getEstado_ocupacion().equals("Disponible")) {
                cbx_Habitaciones.addItem(unaHabitacion);
            }

        }
        if (laHabitacion != null) {
            
            cbx_Habitaciones.setSelectedItem(laHabitacion);
            cbx_Habitaciones.setEnabled(false);
        }else{
        cbx_Habitaciones.setSelectedIndex(0);
        cbx_Habitaciones.setEnabled(true);
        }
        for (Tarifa_Habitacion unaTarifa_Habitacion : tarifas) {
            switch (unaTarifa_Habitacion.getTipo()) {
                case Tarifa_Habitacion.SINGLE:
                    txt_single.setText(String.valueOf(unaTarifa_Habitacion.getPrecio()));
                case Tarifa_Habitacion.DOBLE_MATRIMONIAL:
                case Tarifa_Habitacion.DOBLE_SEPARADA:
                    txt_doble.setText(String.valueOf(unaTarifa_Habitacion.getPrecio()));
                case Tarifa_Habitacion.TRIBLE_MAT_1:
                case Tarifa_Habitacion.TRIBLE_SEPARADA:
                    txt_triple.setText(String.valueOf(unaTarifa_Habitacion.getPrecio()));
                case Tarifa_Habitacion.CUADRUBLE_MAT_2:
                case Tarifa_Habitacion.CUADRUBLE_SEPARADA:
                    txt_cuadruple.setText(String.valueOf(unaTarifa_Habitacion.getPrecio()));


            }
        }

        

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        grupo_Habilitacion = new javax.swing.ButtonGroup();
        grupo_Limpieza = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        cbx_Habitaciones = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        radio_sucia = new javax.swing.JRadioButton();
        radio_deshabilitado = new javax.swing.JRadioButton();
        radio_limpia = new javax.swing.JRadioButton();
        radio_habilitado = new javax.swing.JRadioButton();
        btn_Aceptar = new javax.swing.JButton();
        btn_Cancelar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txt_single = new javax.swing.JTextField();
        txt_doble = new javax.swing.JTextField();
        txt_triple = new javax.swing.JTextField();
        txt_cuadruple = new javax.swing.JTextField();

        setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.LINE_AXIS));

        jTextField1.setEditable(false);
        jTextField1.setBackground(new java.awt.Color(153, 153, 153));
        jTextField1.setFont(new java.awt.Font("Copperplate Gothic Light", 1, 18)); // NOI18N
        jTextField1.setForeground(new java.awt.Color(255, 255, 255));
        jTextField1.setText("Parametros de Habitación");
        jTextField1.setFocusable(false);

        cbx_Habitaciones.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cbx_HabitacionesItemStateChanged(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        jLabel1.setText("Habitacion Número:");

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Opciones de Estado"));

        radio_sucia.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        radio_sucia.setText("Sucia");

        radio_deshabilitado.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        radio_deshabilitado.setText("No Habilitada");

        radio_limpia.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        radio_limpia.setText("Limpia");

        radio_habilitado.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        radio_habilitado.setText("Habilitada");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(radio_habilitado)
                    .addComponent(radio_deshabilitado))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(radio_limpia)
                    .addComponent(radio_sucia))
                .addGap(35, 35, 35))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radio_habilitado)
                    .addComponent(radio_limpia))
                .addGap(12, 12, 12)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radio_deshabilitado)
                    .addComponent(radio_sucia)))
        );

        btn_Aceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Guardar_2.png"))); // NOI18N
        btn_Aceptar.setText("Aceptar");
        btn_Aceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_AceptarActionPerformed(evt);
            }
        });

        btn_Cancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Close.png"))); // NOI18N
        btn_Cancelar.setText("Cancelar");
        btn_Cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_CancelarActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Tarifas de Habitacion"));

        jLabel2.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        jLabel2.setText("Sigles");

        jLabel3.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        jLabel3.setText("Dobles");

        jLabel4.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        jLabel4.setText("Triples");

        jLabel5.setFont(new java.awt.Font("Bookman Old Style", 0, 14)); // NOI18N
        jLabel5.setText("Cuadruples");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txt_doble, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txt_single, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txt_triple, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txt_cuadruple, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(txt_triple, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(txt_cuadruple, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txt_single, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txt_doble, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbx_Habitaciones, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(btn_Aceptar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(btn_Cancelar)))
                .addContainerGap())
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cbx_Habitaciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_Aceptar)
                    .addComponent(btn_Cancelar))
                .addContainerGap())
        );

        add(jPanel1);
    }// </editor-fold>//GEN-END:initComponents

    private void btn_AceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_AceptarActionPerformed
        Habitacion unaHabitacion = (Habitacion) cbx_Habitaciones.getSelectedItem();
        boolean limpia = false;
        boolean habilitada = false;

        if (radio_deshabilitado.isSelected()) {
            habilitada = false;
        } else if (radio_habilitado.isSelected()) {
            habilitada = true;
        }
//        else {
//            JOptionPane.showMessageDialog(this, "Debe seleccionar al menos un Estado de abilitacion");
//        }

        if (radio_limpia.isSelected()) {
            limpia = true;
        } else if (radio_sucia.isSelected()) {
            limpia = false;
        }
//        else {
//            JOptionPane.showMessageDialog(this, "Debe seleccionar al menos un Estado de Limpieza");
//        }

        double precios[] = new double[4];
        double tarifasAnteriores[] = new double[4];

        precios[0] = Double.valueOf(txt_single.getText());
        precios[1] = Double.valueOf(txt_doble.getText());
        precios[2] = Double.valueOf(txt_triple.getText());
        precios[3] = Double.valueOf(txt_cuadruple.getText());

        for (Tarifa_Habitacion unaTarifa_Habitacion : unaHosteria.getTarifas_Habitacion()) {
            switch (unaTarifa_Habitacion.getTipo()) {
                case "Single":
                    tarifasAnteriores[0] = unaTarifa_Habitacion.getPrecio();
                case "Doble Matrimonial":
                case "Doble Separada":
                    tarifasAnteriores[1] = unaTarifa_Habitacion.getPrecio();
                case "Matrimonial + 1":
                case "Trible Separada":
                    tarifasAnteriores[2] = unaTarifa_Habitacion.getPrecio();
                case "Matrimonial + 2":
                case "Cuadruble Separada":
                    tarifasAnteriores[3] = unaTarifa_Habitacion.getPrecio();
            }
        }

        if (precios[0] != tarifasAnteriores[0]) {
            unaHosteria.crearAuditoria("MOD", "Modificó la tarifa de habitacion singles de " + String.valueOf(tarifasAnteriores[0]) + " a " + txt_single.getText(), Acceso.getUsuario(), GUIM.getHoraActual());
        }
        if (precios[1] != tarifasAnteriores[1]) {
            unaHosteria.crearAuditoria("MOD", "Modificó la tarifa de habitacion dobles de " + String.valueOf(tarifasAnteriores[1]) + " a " + txt_doble.getText(), Acceso.getUsuario(), GUIM.getHoraActual());
        }
        if (precios[2] != tarifasAnteriores[2]) {
            unaHosteria.crearAuditoria("MOD", "Modificó la tarifa de habitacion Tribles de " + String.valueOf(tarifasAnteriores[2]) + " a " + txt_triple.getText(), Acceso.getUsuario(), GUIM.getHoraActual());
        }
        if (precios[3] != tarifasAnteriores[3]) {
            unaHosteria.crearAuditoria("MOD", "Modificó la tarifa de habitacion Cuadrubles de " + String.valueOf(tarifasAnteriores[3]) + " a " + txt_cuadruple.getText(), Acceso.getUsuario(), GUIM.getHoraActual());
        }

        unaHosteria.cambiarEstado_Habitacion(unaHabitacion, habilitada, limpia, precios);
        unaHosteria.crearAuditoria("MOD", "Modificó un estado (Habitacion " + unaHabitacion.getNumero() + ")", Acceso.getUsuario(), GUIM.getHoraActual());
//        SwingUtilities.getWindowAncestor(this).dispose();

    }//GEN-LAST:event_btn_AceptarActionPerformed

    private void cbx_HabitacionesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbx_HabitacionesItemStateChanged
        Habitacion unaHabitacion = (Habitacion) cbx_Habitaciones.getSelectedItem();
        if (unaHabitacion.isHabilitado()) {
            radio_habilitado.setSelected(true);
        } else if (!unaHabitacion.isHabilitado()) {
            radio_deshabilitado.setSelected(true);
        }

        if (unaHabitacion.isEstado_limpieza()) {
            radio_limpia.setSelected(true);
        } else if (!unaHabitacion.isEstado_limpieza()) {
            radio_sucia.setSelected(true);
        }

    }//GEN-LAST:event_cbx_HabitacionesItemStateChanged

    private void btn_CancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_CancelarActionPerformed
        SwingUtilities.getWindowAncestor(this).dispose();
    }//GEN-LAST:event_btn_CancelarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_Aceptar;
    private javax.swing.JButton btn_Cancelar;
    private javax.swing.JComboBox cbx_Habitaciones;
    private javax.swing.ButtonGroup grupo_Habilitacion;
    private javax.swing.ButtonGroup grupo_Limpieza;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JRadioButton radio_deshabilitado;
    private javax.swing.JRadioButton radio_habilitado;
    private javax.swing.JRadioButton radio_limpia;
    private javax.swing.JRadioButton radio_sucia;
    private javax.swing.JTextField txt_cuadruple;
    private javax.swing.JTextField txt_doble;
    private javax.swing.JTextField txt_single;
    private javax.swing.JTextField txt_triple;
    // End of variables declaration//GEN-END:variables
}
